Summarizing and Logging

An example of the Summarizing and Logging mode.

Enabling the Summarizing and Logging mode

To enable the Summarizing and Logging mode, you should add !! at the beginning of the code cell.


In [1]:
!!from time import sleep

for i in range(0, 100):
    print(i)
    sleep(0.1)


path: /notebooks/.log/20170704/20170704-071330-0124.log
start time: 2017-07-04 07:13:30(UTC)
end time: 2017-07-04 07:13:40(UTC)
output size: 656 bytes
0 chunks with matched keywords or errors
----
0
...
99

You can configure the summarization settings via the environment variable lc_wrapper.


In [2]:
%env lc_wrapper=4:4:4:4


env: lc_wrapper=4:4:4:4

In [3]:
!!from time import sleep

for i in range(0, 100):
    print(i)
    sleep(0.1)


path: /notebooks/.log/20170704/20170704-071348-0190.log
start time: 2017-07-04 07:13:48(UTC)
end time: 2017-07-04 07:13:58(UTC)
output size: 656 bytes
0 chunks with matched keywords or errors
----
0
1
2
3
...
96
97
98
99

The .log directory is created and the whole of output are recorded on a log file in this directory.

The filename is recorded on output area like above.


In [4]:
!cat /notebooks/.log/20170704/20170704-071348-0190.log


{"lc_cell_meme": {"current": "1c27a2c6-5e2a-11e7-a968-0242ac110003"}}
----
!!from time import sleep

for i in range(0, 100):
    print(i)
    sleep(0.1)
----
path: /notebooks/.log/20170704/20170704-071348-0190.log
start time: 2017-07-04 07:13:48(UTC)
----
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

----
end time: 2017-07-04 07:13:58(UTC)
output size: 158 bytes
0 chunks with matched keywords or errors
----

Various Types of Execution Results

LC_wrapper also records execution results not only stream output.

Plain Text in Execution Result

An execution result is recorded with stream outputs.


In [5]:
def do_something():
    return "output something"

In [6]:
do_something()


Out[6]:
'output something'

In [7]:
!!from time import sleep

for i in range(0, 100):
    print(i)
    sleep(0.1)

do_something()


path: /notebooks/.log/20170704/20170704-071448-0119.log
start time: 2017-07-04 07:14:48(UTC)
end time: 2017-07-04 07:14:58(UTC)
output size: 732 bytes
0 chunks with matched keywords or errors
----
0
1
2
3
...
96
97
98
99
Out[7]:
'output something'

In [8]:
!cat /notebooks/.log/20170704/20170704-071448-0119.log


{"lc_cell_meme": {"current": "932a75fc-56ea-11e7-ba0d-0242ac110002"}}
----
!!from time import sleep

for i in range(0, 100):
    print(i)
    sleep(0.1)

do_something()
----
path: /notebooks/.log/20170704/20170704-071448-0119.log
start time: 2017-07-04 07:14:48(UTC)
----
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

----
end time: 2017-07-04 07:14:58(UTC)
output size: 174 bytes
0 chunks with matched keywords or errors
----
result: /notebooks/.log/20170704/20170704-071448-0119-0.pkl

HTML in Execution Result

Also you can contain HTML code in an exeuction result...


In [9]:
!!from time import sleep
from datetime import datetime
import pandas as pd

items = []
for i in range(0, 100):
    print(i)
    sleep(0.1)
    items.append((i, datetime.now()))

pd.DataFrame(items, columns=['Index', 'Datetime'])


path: /notebooks/.log/20170704/20170704-071539-0790.log
start time: 2017-07-04 07:15:39(UTC)
end time: 2017-07-04 07:15:50(UTC)
output size: 867 bytes
0 chunks with matched keywords or errors
----
0
1
2
3
...
96
97
98
99
Out[9]:
Index Datetime
0 0 2017-07-04 07:15:40.254218
1 1 2017-07-04 07:15:40.355224
2 2 2017-07-04 07:15:40.455753
3 3 2017-07-04 07:15:40.556035
4 4 2017-07-04 07:15:40.656669
5 5 2017-07-04 07:15:40.756945
6 6 2017-07-04 07:15:40.857524
7 7 2017-07-04 07:15:40.957998
8 8 2017-07-04 07:15:41.058410
9 9 2017-07-04 07:15:41.158994
10 10 2017-07-04 07:15:41.259493
11 11 2017-07-04 07:15:41.359999
12 12 2017-07-04 07:15:41.460488
13 13 2017-07-04 07:15:41.560985
14 14 2017-07-04 07:15:41.661581
15 15 2017-07-04 07:15:41.762014
16 16 2017-07-04 07:15:41.862497
17 17 2017-07-04 07:15:41.962989
18 18 2017-07-04 07:15:42.063466
19 19 2017-07-04 07:15:42.163874
20 20 2017-07-04 07:15:42.264358
21 21 2017-07-04 07:15:42.364739
22 22 2017-07-04 07:15:42.465420
23 23 2017-07-04 07:15:42.565930
24 24 2017-07-04 07:15:42.666383
25 25 2017-07-04 07:15:42.766796
26 26 2017-07-04 07:15:42.867228
27 27 2017-07-04 07:15:42.967666
28 28 2017-07-04 07:15:43.068147
29 29 2017-07-04 07:15:43.168652
... ... ...
70 70 2017-07-04 07:15:47.288617
71 71 2017-07-04 07:15:47.389142
72 72 2017-07-04 07:15:47.489628
73 73 2017-07-04 07:15:47.590162
74 74 2017-07-04 07:15:47.690692
75 75 2017-07-04 07:15:47.791134
76 76 2017-07-04 07:15:47.891508
77 77 2017-07-04 07:15:47.991974
78 78 2017-07-04 07:15:48.092389
79 79 2017-07-04 07:15:48.192889
80 80 2017-07-04 07:15:48.293356
81 81 2017-07-04 07:15:48.393835
82 82 2017-07-04 07:15:48.494328
83 83 2017-07-04 07:15:48.594845
84 84 2017-07-04 07:15:48.695299
85 85 2017-07-04 07:15:48.795801
86 86 2017-07-04 07:15:48.896254
87 87 2017-07-04 07:15:48.996703
88 88 2017-07-04 07:15:49.097184
89 89 2017-07-04 07:15:49.197463
90 90 2017-07-04 07:15:49.298048
91 91 2017-07-04 07:15:49.398637
92 92 2017-07-04 07:15:49.499141
93 93 2017-07-04 07:15:49.599543
94 94 2017-07-04 07:15:49.700122
95 95 2017-07-04 07:15:49.800542
96 96 2017-07-04 07:15:49.900961
97 97 2017-07-04 07:15:50.001429
98 98 2017-07-04 07:15:50.101900
99 99 2017-07-04 07:15:50.202352

100 rows × 2 columns


In [10]:
!cat /notebooks/.log/20170704/20170704-071539-0790.log


{"lc_cell_meme": {"current": "81c9561e-5e2b-11e7-a968-0242ac110003"}}
----
!!from time import sleep
from datetime import datetime
import pandas as pd

items = []
for i in range(0, 100):
    print(i)
    sleep(0.1)
    items.append((i, datetime.now()))

pd.DataFrame(items, columns=['Index', 'Datetime'])
----
path: /notebooks/.log/20170704/20170704-071539-0790.log
start time: 2017-07-04 07:15:39(UTC)
----
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

----
end time: 2017-07-04 07:15:50(UTC)
output size: 309 bytes
0 chunks with matched keywords or errors
----
result: /notebooks/.log/20170704/20170704-071539-0790-0.pkl

Image in Execution Result


In [11]:
%matplotlib inline

In [12]:
!!from time import sleep
from datetime import datetime
import pandas as pd

items = []
for i in range(0, 100):
    print(i)
    sleep(0.1)
    items.append((datetime.now(), i))

pd.DataFrame(items, columns=['Datetime', 'Index']).set_index('Datetime').plot()


path: /notebooks/.log/20170704/20170704-071619-0567.log
start time: 2017-07-04 07:16:19(UTC)
end time: 2017-07-04 07:16:29(UTC)
output size: 956 bytes
0 chunks with matched keywords or errors
----
0
1
2
3
...
96
97
98
99
Out[12]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fa8c77b1f10>

In [13]:
!cat /notebooks/.log/20170704/20170704-071619-0567.log


{"lc_cell_meme": {"current": "c9514668-5e2b-11e7-a968-0242ac110003"}}
----
!!from time import sleep
from datetime import datetime
import pandas as pd

items = []
for i in range(0, 100):
    print(i)
    sleep(0.1)
    items.append((datetime.now(), i))

pd.DataFrame(items, columns=['Datetime', 'Index']).set_index('Datetime').plot()
----
path: /notebooks/.log/20170704/20170704-071619-0567.log
start time: 2017-07-04 07:16:19(UTC)
----
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

----
end time: 2017-07-04 07:16:29(UTC)
output size: 338 bytes
0 chunks with matched keywords or errors
----
result: /notebooks/.log/20170704/20170704-071619-0567-0.pkl
result: /notebooks/.log/20170704/20170704-071619-0567-1.pkl

Errors

lc_wrapper can handle errors properly.


In [14]:
!!from time import sleep

for i in range(0, 100):
    print(i)
    sleep(0.1)

# Always raises AssertionError
assert False


path: /notebooks/.log/20170704/20170704-071647-0970.log
start time: 2017-07-04 07:16:47(UTC)
end time: 2017-07-04 07:16:58(UTC)
output size: 761 bytes
0 chunks with matched keywords or errors
----
0
1
2
3
...
96
97
98
99

AssertionErrorTraceback (most recent call last)
<ipython-input-28-5ce67cc1e015> in <module>()
      6 
      7 # Always raises AssertionError
----> 8 assert False

AssertionError: 

In [15]:
!cat /notebooks/.log/20170704/20170704-071647-0970.log


{"lc_cell_meme": {"current": "932a773c-56ea-11e7-ba0d-0242ac110002"}}
----
!!from time import sleep

for i in range(0, 100):
    print(i)
    sleep(0.1)

# Always raises AssertionError
assert False
----
path: /notebooks/.log/20170704/20170704-071647-0970.log
start time: 2017-07-04 07:16:47(UTC)
----
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

----
end time: 2017-07-04 07:16:58(UTC)
output size: 203 bytes
0 chunks with matched keywords or errors
----
result: /notebooks/.log/20170704/20170704-071647-0970-0.pkl

In [ ]: